<?php
require_once("mysql.inc.php");
require_once("checkLogin.inc.php");

if(isset($_GET["title"]) && isset($_GET["author"])) {
	getBook($_GET["title"], $_GET["author"]);
}

function getBook($title, $author) {

	$title = mysql_real_escape_string($title);
	$author = mysql_real_escape_string($author);
	
	$result = mysql_query("SELECT * FROM `books` WHERE `title`='$title' AND `author`='$author'") or die(mysql_error());
	$fetch = mysql_fetch_array($result);
	
	$no_info = "Niet bekend";
	
	//create new dom document
	$doc = new DomDocument('1.0');
	$root = $doc->createElement("results");
	$doc->appendChild($root);
	
	$t = $doc->createElement("title");
	if(!empty($fetch["title"])) {
		$t->appendChild($doc->createTextNode($fetch["title"]));
	}
	else {
		$t->appendChild($doc->createTextNode($no_info));
	}		
	$root->appendChild($t);
		
	$a = $doc->createElement("author");
	if(!empty($fetch["author"])) {
		$a->appendChild($doc->createTextNode($fetch["author"]));
	}
	else {
		$a->appendChild($doc->createTextNode($no_info));
	}		
	$root->appendChild($a);
		
	$a2 = $doc->createElement("author2");
	if(!empty($fetch["author2"])) {
		$a2->appendChild($doc->createTextNode($fetch["author2"]));
	}
	else {
		$a2->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($a2);
		
	$genre = $doc->createElement("genre");
	if(!empty($fetch["genre"])) {
		$genre->appendChild($doc->createTextNode($fetch["genre"]));
	}
	else {
		$genre->appendChild($doc->createTextNode($no_info));
	}	
	$root->appendChild($genre);
		
	$theme = $doc->createElement("theme1");
	if(!empty($fetch["theme1"])) {
		$theme->appendChild($doc->createTextNode($fetch["theme1"]));
	}
	else {
		$theme->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($theme);
		
	$theme2 = $doc->createElement("theme2");
	if(!empty($fetch["theme2"])) {
		$theme2->appendChild($doc->createTextNode($fetch["theme2"]));	
	}
	else {
		$theme2->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($theme2);
		
	$price = $doc->createElement("price");
	if(!empty($fetch["price"])) {
		$price->appendChild($doc->createTextNode($fetch["price"]));	
	}
	else {
		$price->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($price);
		
	$age = $doc->createElement("age");
	if(!empty($fetch["age"])) {
		$age->appendChild($doc->createTextNode($fetch["age"]));	
	}
	else {
		$age->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($age);
		
	$publisher = $doc->createElement("publish");
	if(!empty($fetch["publisher"])) {
		$publisher->appendChild($doc->createTextNode($fetch["publisher"]));	
	}
	else {
		$publisher->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($publisher);
		
	$place = $doc->createElement("place");
	if(!empty($fetch["place"])) {
		$place->appendChild($doc->createTextNode($fetch["place"]));	
	}
	else {
		$place->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($place);
		
	$material = $doc->createElement("material");
	if(!empty($fetch["material"])) {
		$material->appendChild($doc->createTextNode($fetch["material"]));	
	}
	else {
		$material->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($material);
		
	$avaible = $doc->createElement("avaible");
	if(!empty($fetch["avaible"])) {
		$avaible->appendChild($doc->createTextNode($fetch["avaible"]));	
	}
	else {
		$avaible->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($avaible);
	
	$likes = $doc->createElement("likes");
	if(!empty($fetch["likes"])) {
		$likes->appendChild($doc->createTextNode($fetch["likes"]));
	}
	else {
		$likes->appendChild($doc->createTextNode($no_info));
	}
	$root->appendChild($likes);
	
	$info = $doc->createElement("info");
	if(!empty($fetch["info"])) {
		$info->appendChild($doc->createTextNode($fetch["info"]));
	}
	else {
		$info->appendChild($doc->createTextNode($fetch["title"] . "-" . $fetch["author"]));
	}
	$root->appendChild($info);
	
	echo $doc->saveXML();
	
}
?>